package com.jpyl.jpMedicalTreatment.view.activity;

import android.os.Bundle;
import android.widget.Button;

import com.forxindu.kit.box.ViewKit;
import com.google.gson.JsonObject;
import com.jakewharton.rxbinding.view.RxView;
import com.jpyl.jpMedicalTreatment.R;
import com.jpyl.jpMedicalTreatment.model.AgentMessageModel;
import com.jpyl.jpMedicalTreatment.model.CompleteModel;
import com.jpyl.jpMedicalTreatment.model.ErrorMessageModel;
import com.jpyl.jpMedicalTreatment.model.IsSignModel;
import com.jpyl.jpMedicalTreatment.model.NewsMessageModel;
import com.jpyl.jpMedicalTreatment.model.OlderStateModel;
import com.jpyl.jpMedicalTreatment.model.OrderMessageModel;
import com.jpyl.jpMedicalTreatment.model.OutSituationModel;
import com.jpyl.jpMedicalTreatment.model.ProductsMessageModel;
import com.jpyl.jpMedicalTreatment.model.QueryUserModel;
import com.jpyl.jpMedicalTreatment.model.ResponseModel;
import com.jpyl.jpMedicalTreatment.model.RowsPeripheralModel;
import com.jpyl.jpMedicalTreatment.model.UserMessageModel;
import com.jpyl.jpMedicalTreatment.model.WeiXinPayModel;
import com.jpyl.jpMedicalTreatment.network.Network;
import com.jpyl.jpMedicalTreatment.network.api.ApiError;
import com.jpyl.jpMedicalTreatment.network.api.RequestApi;

import java.util.List;
import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

/**
 * Created by 521546564465 on 2019/3/2.
 */

public class TestActivity extends BaseActivity {

    @BindView(R.id.jpylLogin)
    Button jpylLogin;

    @BindView(R.id.jpylLogout)
    Button jpylLogout;

    @BindView(R.id.jpylRegister)
    Button jpylRegister;

    @BindView(R.id.jpylChangePassword)
    Button jpylChangePassword;

    @BindView(R.id.jpylRestorePassword)
    Button jpylRestorePassword;

    @BindView(R.id.QueryUserById)
    Button QueryUserById;

    @BindView(R.id.QueryUserByLoginname)
    Button QueryUserByLoginname;

    @BindView(R.id.QueryAreaAgentByName)
    Button QueryAreaAgentByName;

    @BindView(R.id.QueryAgentByName)
    Button QueryAgentByName;

    @BindView(R.id.QueryDoctorsByName)
    Button QueryDoctorsByName;

    @BindView(R.id.QueryMyAgentByName)
    Button QueryMyAgentByName;

    @BindView(R.id.QueryMyDoctorByName)
    Button QueryMyDoctorByName;

    @BindView(R.id.MyPatientsByName)
    Button MyPatientsByName;

    @BindView(R.id.lEditUser)
    Button lEditUser;

    @BindView(R.id.CheckTodaySign)
    Button CheckTodaySign;

    @BindView(R.id.Sign)
    Button Sign;

    @BindView(R.id.GetAds)
    Button GetAds;

    @BindView(R.id.GetNews)
    Button GetNews;

    @BindView(R.id.GetProducts)
    Button GetProducts;

    @BindView(R.id.GetSaleProducts)
    Button GetSaleProducts;

    @BindView(R.id.GetBypointProducts)
    Button GetBypointProducts;

    @BindView(R.id.GetHPV)
    Button GetHPV;


    @BindView(R.id.GetHP)
    Button GetHP;

    @BindView(R.id.GetSe)
    Button GetSe;

    @BindView(R.id.Complain)
    Button Complain;

    @BindView(R.id.lOrder)
    Button lOrder;

    @BindView(R.id.GetOrderInfoById)
    Button GetOrderInfoById;

    @BindView(R.id.PayOrder)
    Button PayOrder;

    @BindView(R.id.GetZFBPayInfo)
    Button GetZFBPayInfo;

    @BindView(R.id.GetWXPayInfo)
    Button GetWXPayInfo;

    @BindView(R.id.CheckOrderPaySuccess)
    Button CheckOrderPaySuccess;

    @BindView(R.id.TryRefundOrder)
    Button TryRefundOrder;

    @BindView(R.id.CancelOrder)
    Button CancelOrder;

    @BindView(R.id.BuyerOrders)
    Button BuyerOrders;

    @BindView(R.id.OwnerShipOrders)
    Button OwnerShipOrders;

    @BindView(R.id.AreaAgentShipOrders)
    Button AreaAgentShipOrders;

    @BindView(R.id.MyAreaAgentStatiticsForOwner)
    Button MyAreaAgentStatiticsForOwner;

    @BindView(R.id.MyAgentStatiticsForAreaAgent)
    Button MyAgentStatiticsForAreaAgent;

    @BindView(R.id.MyDoctorStatitics)
    Button MyDoctorStatitics;

    @BindView(R.id.AgentShipOrders)
    Button AgentShipOrders;

    @BindView(R.id.AgentDPStatitic)
    Button AgentDPStatitic;

    @BindView(R.id.MyPatientResults)
    Button MyPatientResults;

    @BindView(R.id.MyPatientShipOrders)
    Button MyPatientShipOrders;


    @BindView(R.id.MyPatientStatistics)
    Button MyPatientStatistics;

    @BindView(R.id.CheckUserCompleteInfo)
    Button CheckUserCompleteInfo;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_test;
    }

    @Override
    public void afterCreate(Bundle savedInstanceState) {
        RxView.clicks(jpylLogin)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        login();
                    }
                });

        RxView.clicks(jpylLogout)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        Logout();
                    }
                });

        RxView.clicks(jpylRegister)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        Register();
                    }
                });
        RxView.clicks(jpylChangePassword)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        ChangePassword();
                    }
                });
        RxView.clicks(jpylRestorePassword)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        RestorePassword();
                    }
                });
        RxView.clicks(QueryUserById)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        jpylQueryUserById();
                    }
                });
        RxView.clicks(QueryUserByLoginname)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        jpylQueryUserByLoginname();
                    }
                });
        RxView.clicks(QueryAreaAgentByName)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        jpylQueryAreaAgentByName();
                    }
                });
        RxView.clicks(QueryAgentByName)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        jpylQueryAgentByName();
                    }
                });
        RxView.clicks(QueryDoctorsByName)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        jpylQueryDoctorsByName();
                    }
                });
        RxView.clicks(QueryMyAgentByName)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {

                    }
                });
        RxView.clicks(QueryMyDoctorByName)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {

                    }
                });
        RxView.clicks(MyPatientsByName)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {

                    }
                });
        RxView.clicks(lEditUser)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        jpylEditUser();
                    }
                });
        //今天是否签到
        RxView.clicks(CheckTodaySign)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        jpylCheckTodaySign();
                    }
                });
        RxView.clicks(Sign)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        jpylSign();
                    }
                });
        RxView.clicks(GetAds)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        GetAds();
                    }
                });
        RxView.clicks(GetNews)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        jpylGetNews();
                    }
                });
        RxView.clicks(GetProducts)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        jpylGetProducts();
                    }
                });
        RxView.clicks(GetSaleProducts)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        jpylGetSaleProducts();
                    }
                });
        RxView.clicks(GetBypointProducts)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        jpylGetBypointProducts();
                    }
                });
        RxView.clicks(CheckUserCompleteInfo)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        jpylCheckUserCompleteInfo();
                    }
                });

        RxView.clicks(GetHPV)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
//                        jpylGetHPV();
                    }
                });

        RxView.clicks(GetHP)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
//                        jpylGetHP();
                    }
                });
        RxView.clicks(GetSe)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
//                        jpylGetSe();
                    }
                });
        RxView.clicks(Complain)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        jpylComplain();
                    }
                });
        RxView.clicks(lOrder)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        jpylOrder();
                    }
                });
        RxView.clicks(GetOrderInfoById)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        jpylGetOrderInfoById();
                    }
                });
        RxView.clicks(PayOrder)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        jpylPayOrder();
                    }
                });
        RxView.clicks(GetZFBPayInfo)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        jpylGetZFBPayInfo();
                    }
                });
        RxView.clicks(GetWXPayInfo)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        jpylGetWXPayInfo();
                    }
                });
        RxView.clicks(CheckOrderPaySuccess)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        jpylCheckOrderPaySuccess();
                    }
                });
        RxView.clicks(TryRefundOrder)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        jpylTryRefundOrder();
                    }
                });
        RxView.clicks(CancelOrder)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        jpylCancelOrder();
                    }
                });
        RxView.clicks(BuyerOrders)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
//                        jpylBuyerOrders();
                    }
                });
        RxView.clicks(OwnerShipOrders)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
//                        jpylOwnerShipOrders();
                    }
                });
        RxView.clicks(AreaAgentShipOrders)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
//                        jpylAreaAgentShipOrders();
                    }
                });
        RxView.clicks(MyAreaAgentStatiticsForOwner)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        jpylMyAreaAgentStatiticsForOwner();
                    }
                });
        RxView.clicks(MyAgentStatiticsForAreaAgent)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
//                        jpylMyAgentStatiticsForAreaAgent();
                    }
                });
        RxView.clicks(MyDoctorStatitics)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        jpylMyDoctorStatitics();
                    }
                });
        RxView.clicks(AgentShipOrders)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
//                        jpylAgentShipOrders();
                    }
                });
        RxView.clicks(AgentDPStatitic)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
//                        jpylAgentDPStatitics();
                    }
                });
        RxView.clicks(MyPatientResults)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        jpylMyPatientResults();
                    }
                });
        RxView.clicks(MyPatientShipOrders)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
                        jpylMyPatientShipOrders();
                    }
                });
        RxView.clicks(MyPatientStatistics)
                .throttleFirst(200, TimeUnit.MICROSECONDS)
                .subscribe(new Action1<Void>() {
                    @Override
                    public void call(Void aVoid) {
//                        jpylMyPatientStatistics();
                    }
                });

    }

    final RequestApi publicApi = Network.getRequestApi();

    /**
     * 登录
     * param
     */
    private void login() {

        String loginName = "18600000001";
        String password = "1";
        final JsonObject body = new JsonObject();
        body.addProperty("province", "天津");

        publicApi.login(loginName, password, body.toString()).map(new Func1<ResponseModel<UserMessageModel>,
                UserMessageModel>() {
            @Override
            public UserMessageModel call(ResponseModel<UserMessageModel> responseModel) {
                if (responseModel.getCode() != 0) {
                    String msg = responseModel.getMsg();
                    throw new ApiError(responseModel.getCode(), msg);
                }
                return responseModel.getData();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<UserMessageModel>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                        }
                    }

                    @Override
                    public void onNext(UserMessageModel userModel) {

                    }
                });
    }

    void Logout() {
        String loginname = "18622054484";
        publicApi.jpylLogout(loginname).map(new Func1<ResponseModel<String>,
                String>() {
            @Override
            public String call(ResponseModel<String> responseModel) {
                if (responseModel.getCode() != 0) {
                    String msg = responseModel.getMsg();
                    throw new ApiError(responseModel.getCode(), msg);
                }
                return responseModel.getMsg();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<String>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                            ViewKit.showToast(TestActivity.this, error.getMsg() + "");
                        }
                    }

                    @Override
                    public void onNext(String msg) {
                        ViewKit.showToast(TestActivity.this, msg + "");
                    }
                });
    }

    void Register() {

        String loginname = "18622054484";
        String password = "1";
        //邀请人，邀请人则增加积分
        String inviter = "18622054487";

        publicApi.jpylRegister(loginname, password, inviter).map(new Func1<ResponseModel<String>,
                String>() {
            @Override
            public String call(ResponseModel<String> responseModel) {
                if (responseModel.getCode() != 0) {
                    String msg = responseModel.getMsg();
                    throw new ApiError(responseModel.getCode(), msg);
                }
                return responseModel.getMsg();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<String>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                            ViewKit.showToast(TestActivity.this, error.getMsg() + "");
                        }
                    }

                    @Override
                    public void onNext(String msg) {
                        ViewKit.showToast(TestActivity.this, msg + "");
                    }
                });
    }

    void ChangePassword() {
        String loginname = "18622054484";
        String oldPassword = "1";
        String newPassword = "12";

        publicApi.jpylChangePassword(loginname, oldPassword, newPassword).map(new Func1<ResponseModel<String>,
                String>() {
            @Override
            public String call(ResponseModel<String> responseModel) {
                if (responseModel.getCode() != 0) {
                    String msg = responseModel.getMsg();
                    throw new ApiError(responseModel.getCode(), msg);
                }
                return responseModel.getMsg();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<String>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                            ViewKit.showToast(TestActivity.this, error.getMsg() + "");
                        }
                    }

                    @Override
                    public void onNext(String msg) {
                        ViewKit.showToast(TestActivity.this, msg + "");
                    }
                });
    }

    //用户名用来初始化密码，需在移动端经过验证码验证
    void RestorePassword() {

        String loginname = "18622054484";

        publicApi.jpylRestorePassword(loginname).map(new Func1<ResponseModel<String>,
                String>() {
            @Override
            public String call(ResponseModel<String> responseModel) {
                if (responseModel.getCode() != 0) {
                    String msg = responseModel.getMsg();
                    throw new ApiError(responseModel.getCode(), msg);
                }
                return responseModel.getMsg();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<String>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                            ViewKit.showToast(TestActivity.this, error.getMsg() + "");
                        }
                    }

                    @Override
                    public void onNext(String msg) {
                        ViewKit.showToast(TestActivity.this, msg + "");
                    }
                });
    }

    //获得广告
    void GetAds() {
        publicApi.jpylGetAds().map(new Func1<ResponseModel<RowsPeripheralModel>,
                RowsPeripheralModel>() {
            @Override
            public RowsPeripheralModel call(ResponseModel<RowsPeripheralModel> responseModel) {
                if (responseModel.getCode() != 0) {
                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
                    throw new ApiError(messageModel);
                }
                return responseModel.getData();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<RowsPeripheralModel>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                        }
                    }

                    @Override
                    public void onNext(RowsPeripheralModel model) {

                    }
                });
    }

    private void jpylQueryUserById() {

        String userid = "859d51105bbc407c8e96f3b5e94336fe";

        publicApi.jpylQueryUserById(userid).map(new Func1<ResponseModel<QueryUserModel>, QueryUserModel>() {
            @Override
            public QueryUserModel call(ResponseModel<QueryUserModel> responseModel) {
                if (responseModel.getCode() != 0) {
                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
                    throw new ApiError(messageModel);
                }
                return responseModel.getData();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<QueryUserModel>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                        } else {
                        }
                    }

                    @Override
                    public void onNext(QueryUserModel model) {

                    }
                });
    }

    private void jpylQueryUserByLoginname() {

        String loginname = "18698022818";

        publicApi.jpylQueryUserByLoginname(loginname).map(new Func1<ResponseModel<QueryUserModel>, QueryUserModel>() {
            @Override
            public QueryUserModel call(ResponseModel<QueryUserModel> responseModel) {
                if (responseModel.getCode() != 0) {
                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
                    throw new ApiError(messageModel);
                }
                return responseModel.getData();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<QueryUserModel>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                        } else {
                        }
                    }

                    @Override
                    public void onNext(QueryUserModel model) {

                    }
                });
    }

    private void jpylQueryAreaAgentByName() {

        String name = "胡";

        publicApi.jpylQueryAreaAgentByName(name).map(new Func1<ResponseModel<List<AgentMessageModel>>, List<AgentMessageModel>>() {
            @Override
            public List<AgentMessageModel> call(ResponseModel<List<AgentMessageModel>> responseModel) {
                if (responseModel.getCode() != 0) {
                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
                    throw new ApiError(messageModel);
                }
                return responseModel.getData();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<List<AgentMessageModel>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                        } else {
                        }
                    }

                    @Override
                    public void onNext(List<AgentMessageModel> list) {

                    }
                });
    }

    private void jpylQueryAgentByName() {

        String name = "";

        publicApi.jpylQueryAgentByName(name).map(new Func1<ResponseModel<List<AgentMessageModel>>, List<AgentMessageModel>>() {
            @Override
            public List<AgentMessageModel> call(ResponseModel<List<AgentMessageModel>> responseModel) {
                if (responseModel.getCode() != 0) {
                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
                    throw new ApiError(messageModel);
                }
                return responseModel.getData();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<List<AgentMessageModel>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                        } else {
                        }
                    }

                    @Override
                    public void onNext(List<AgentMessageModel> list) {

                    }
                });
    }

    private void jpylQueryDoctorsByName() {

        String name = "医生";

        publicApi.jpylQueryDoctorsByName(name).map(new Func1<ResponseModel<List<AgentMessageModel>>, List<AgentMessageModel>>() {
            @Override
            public List<AgentMessageModel> call(ResponseModel<List<AgentMessageModel>> responseModel) {
                if (responseModel.getCode() != 0) {
                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
                    throw new ApiError(messageModel);
                }
                return responseModel.getData();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<List<AgentMessageModel>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                        } else {
                        }
                    }

                    @Override
                    public void onNext(List<AgentMessageModel> list) {

                    }
                });
    }

    void jpylEditUser() {

        final JsonObject body = new JsonObject();
        body.addProperty("id", "859d51105bbc407c8e96f3b5e94336fe");
        body.addProperty("username", "患者1");
        body.addProperty("gender", 0);
        body.addProperty("birthday", "1983年10月29日");
        body.addProperty("nation", 0);
        body.addProperty("email", "leonlian007@hotmail.com");
        body.addProperty("address", "天津市天津市南开区");
        body.addProperty("doctorid", "4381d2abbf7d4abbb86f4cb353d98245");
        body.addProperty("cid", "120101111111111111");

//        publicApi.jpylEditUser(body).map(new Func1<ResponseModel<Object>,
//                Object>() {
//            @Override
//            public Object call(ResponseModel<Object> responseModel) {
//                if (responseModel.getCode() != 0) {
//                    String msg = responseModel.getMsg();
//                    throw new ApiError(responseModel.getCode(), msg);
//                }
//                return responseModel.getMsg();
//            }
//        })
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Subscriber<Object>() {
//                    @Override
//                    public void onCompleted() {
//
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//                        e.printStackTrace();
//                        if (e instanceof ApiError) {
//                            ApiError error = (ApiError) e;
//                            ViewKit.showToast(TestActivity.this, error.getMsg() + "");
//                        }
//                    }
//
//                    @Override
//                    public void onNext(Object object) {
//
//                    }
//                });
    }

    private void jpylCheckTodaySign() {

        String userid = "761f1cc86a2340beaa7c89115d96327c";

        publicApi.jpylCheckTodaySign(userid).map(new Func1<ResponseModel<IsSignModel>, IsSignModel>() {
            @Override
            public IsSignModel call(ResponseModel<IsSignModel> responseModel) {
                if (responseModel.getCode() != 0) {
                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
                    throw new ApiError(messageModel);
                }
                return responseModel.getData();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<IsSignModel>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                        } else {
                        }
                    }

                    @Override
                    public void onNext(IsSignModel model) {

                    }
                });
    }

    //签到
    void jpylSign() {

        String userid = "761f1cc86a2340beaa7c89115d96327";

        publicApi.jpylSign(userid).map(new Func1<ResponseModel<String>,
                String>() {
            @Override
            public String call(ResponseModel<String> responseModel) {
                if (responseModel.getCode() != 0) {
                    String msg = responseModel.getMsg();
                    throw new ApiError(responseModel.getCode(), msg);
                }
                return responseModel.getMsg();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<String>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                            ViewKit.showToast(TestActivity.this, error.getMsg() + "");
                        }
                    }

                    @Override
                    public void onNext(String msg) {
                        ViewKit.showToast(TestActivity.this, msg + "");
                    }
                });
    }

    private void jpylGetNews() {

        final JsonObject body = new JsonObject();
        body.addProperty("rows", "10");
        body.addProperty("page", "1");

        publicApi.jpylGetNews(body.toString()).map(new Func1<ResponseModel<NewsMessageModel>, NewsMessageModel>() {
            @Override
            public NewsMessageModel call(ResponseModel<NewsMessageModel> responseModel) {
                if (responseModel.getCode() != 0) {
                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
                    throw new ApiError(messageModel);
                }
                return responseModel.getData();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<NewsMessageModel>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                        } else {
                        }
                    }

                    @Override
                    public void onNext(NewsMessageModel model) {

                    }
                });
    }

    private void jpylGetProducts() {

        final JsonObject body = new JsonObject();
        body.addProperty("rows", "10");
        body.addProperty("page", "1");

        publicApi.jpylGetProducts(body.toString()).map(new Func1<ResponseModel<ProductsMessageModel>, ProductsMessageModel>() {
            @Override
            public ProductsMessageModel call(ResponseModel<ProductsMessageModel> responseModel) {
                if (responseModel.getCode() != 0) {
                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
                    throw new ApiError(messageModel);
                }
                return responseModel.getData();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<ProductsMessageModel>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                        } else {
                        }
                    }

                    @Override
                    public void onNext(ProductsMessageModel model) {

                    }
                });
    }

    private void jpylGetSaleProducts() {

        final JsonObject body = new JsonObject();
        body.addProperty("rows", "10");
        body.addProperty("page", "1");

        publicApi.jpylGetSaleProducts(body.toString()).map(new Func1<ResponseModel<ProductsMessageModel>, ProductsMessageModel>() {
            @Override
            public ProductsMessageModel call(ResponseModel<ProductsMessageModel> responseModel) {
                if (responseModel.getCode() != 0) {
                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
                    throw new ApiError(messageModel);
                }
                return responseModel.getData();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<ProductsMessageModel>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                        } else {
                        }
                    }

                    @Override
                    public void onNext(ProductsMessageModel model) {

                    }
                });
    }

    private void jpylGetBypointProducts() {

        final JsonObject body = new JsonObject();
        body.addProperty("rows", "10");
        body.addProperty("page", "1");

        publicApi.jpylGetBypointProducts(body.toString()).map(new Func1<ResponseModel<ProductsMessageModel>, ProductsMessageModel>() {
            @Override
            public ProductsMessageModel call(ResponseModel<ProductsMessageModel> responseModel) {
                if (responseModel.getCode() != 0) {
                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
                    throw new ApiError(messageModel);
                }
                return responseModel.getData();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<ProductsMessageModel>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                        } else {
                        }
                    }

                    @Override
                    public void onNext(ProductsMessageModel model) {

                    }
                });
    }

    private void jpylCheckUserCompleteInfo() {

        String userid = "859d51105bbc407c8e96f3b5e94336fe";
        final JsonObject body = new JsonObject();
        body.addProperty("rows", "10");
        body.addProperty("page", "1");

        publicApi.jpylCheckUserCompleteInfo(userid, body.toString()).map(new Func1<ResponseModel<CompleteModel>, CompleteModel>() {
            @Override
            public CompleteModel call(ResponseModel<CompleteModel> responseModel) {
                if (responseModel.getCode() != 0) {
                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
                    throw new ApiError(messageModel);
                }
                return responseModel.getData();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<CompleteModel>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                        } else {
                        }
                    }

                    @Override
                    public void onNext(CompleteModel object) {

                    }
                });
    }

//    private void jpylGetHP() {
//
//        final JsonObject body = new JsonObject();
//        body.addProperty("rows", "10");
//        body.addProperty("page", "1");
//        String userid = "859d51105bbc407c8e96f3b5e94336fe";
//        int dateFrom = 0;
//        int dateTo = 0;
//
//        publicApi.jpylGetHP(userid, body.toString(), dateFrom, dateTo).map(new Func1<ResponseModel<UserModel>, UserModel>() {
//            @Override
//            public UserModel call(ResponseModel<UserModel> responseModel) {
//                if (responseModel.getCode() != 0) {
//                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
//                    throw new ApiError(messageModel);
//                }
//                return responseModel.getData();
//            }
//        })
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Subscriber<UserModel>() {
//                    @Override
//                    public void onCompleted() {
//
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//                        e.printStackTrace();
//                        if (e instanceof ApiError) {
//                            ApiError error = (ApiError) e;
//                        } else {
//                        }
//                    }
//
//                    @Override
//                    public void onNext(UserModel userModel) {
//
//                    }
//                });
//    }
//
//    private void jpylGetSe() {
//
//        final JsonObject body = new JsonObject();
//        body.addProperty("rows", "10");
//        body.addProperty("page", "1");
//        String userid = "859d51105bbc407c8e96f3b5e94336fe";
//        int dateFrom = 0;
//        int dateTo = 0;
//
//        publicApi.jpylGetSe(userid, body.toString(), dateFrom, dateTo).map(new Func1<ResponseModel<UserModel>, UserModel>() {
//            @Override
//            public UserModel call(ResponseModel<UserModel> responseModel) {
//                if (responseModel.getCode() != 0) {
//                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
//                    throw new ApiError(messageModel);
//                }
//                return responseModel.getData();
//            }
//        })
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Subscriber<UserModel>() {
//                    @Override
//                    public void onCompleted() {
//
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//                        e.printStackTrace();
//                        if (e instanceof ApiError) {
//                            ApiError error = (ApiError) e;
//                        } else {
//                        }
//                    }
//
//                    @Override
//                    public void onNext(UserModel userModel) {
//
//                    }
//                });
//    }

    void jpylComplain() {

        String userid = "18622054484";
        String content = "东西又烂又贵，能退货吗";

        publicApi. jpylComplain(userid,content).map(new Func1<ResponseModel<String>,
                String>() {
            @Override
            public String call(ResponseModel<String> responseModel) {
                if (responseModel.getCode() != 0) {
                    String msg = responseModel.getMsg();
                    throw new ApiError(responseModel.getCode(), msg);
                }
                return responseModel.getMsg();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<String>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                            ViewKit.showToast(TestActivity.this, error.getMsg() + "");
                        }
                    }

                    @Override
                    public void onNext(String msg) {
                        ViewKit.showToast(TestActivity.this, msg + "");
                    }
                });
    }

    private void jpylOrder() {

        String userid = "859d51105bbc407c8e96f3b5e94336fe";
        int type = 0;
        String province = "";
        String address = "天津市天津市南开区";
        String productid = "228ba44bbcbf4a13929387e3c3741075";
        int number = 2;

        publicApi.jpylOrder(userid, type, province, address,productid,number).map(new Func1<ResponseModel<OrderMessageModel>, OrderMessageModel>() {
            @Override
            public OrderMessageModel call(ResponseModel<OrderMessageModel> responseModel) {
                if (responseModel.getCode() != 0) {
                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
                    throw new ApiError(messageModel);
                }
                return responseModel.getData();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<OrderMessageModel>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                        } else {
                        }
                    }

                    @Override
                    public void onNext(OrderMessageModel model) {

                    }
                });
    }

    private void jpylGetOrderInfoById() {
//
//        String orderid = "8d25b90b995a461aa57212ca3ac8af73";
//
//        publicApi.jpylGetOrderInfoById(orderid).map(new Func1<ResponseModel<OrderMessageModel>, OrderMessageModel>() {
//            @Override
//            public OrderMessageModel call(ResponseModel<OrderMessageModel> responseModel) {
//                if (responseModel.getCode() != 0) {
//                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
//                    throw new ApiError(messageModel);
//                }
//                return responseModel.getData();
//            }
//        })
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Subscriber<OrderMessageModel>() {
//                    @Override
//                    public void onCompleted() {
//
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//                        e.printStackTrace();
//                        if (e instanceof ApiError) {
//                            ApiError error = (ApiError) e;
//                        } else {
//                        }
//                    }
//
//                    @Override
//                    public void onNext(OrderMessageModel model) {
//
//                    }
//                });
    }


    void jpylPayOrder() {

        String userid = "859d51105bbc407c8e96f3b5e94336fe";
        String orderid = "d12365baeaf54707933f83540d760edb";

        publicApi.jpylPayOrder(userid,orderid).map(new Func1<ResponseModel<String>,
                String>() {
            @Override
            public String call(ResponseModel<String> responseModel) {
                if (responseModel.getCode() != 0) {
                    String msg = responseModel.getMsg();
                    throw new ApiError(responseModel.getCode(), msg);
                }
                return responseModel.getMsg();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<String>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                            ViewKit.showToast(TestActivity.this, error.getMsg() + "");
                        }
                    }

                    @Override
                    public void onNext(String msg) {
                        ViewKit.showToast(TestActivity.this, msg + "");
                    }
                });
    }

    void jpylGetZFBPayInfo() {

        String orderid = "d12365baeaf54707933f83540d760edb";

        publicApi.jpylGetZFBPayInfo(orderid).map(new Func1<ResponseModel<String>,
                String>() {
            @Override
            public String call(ResponseModel<String> responseModel) {
                if (responseModel.getCode() != 0) {
                    String msg = responseModel.getMsg();
                    throw new ApiError(responseModel.getCode(), msg);
                }
                return responseModel.getMsg();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<String>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                            ViewKit.showToast(TestActivity.this, error.getMsg() + "");
                        }
                    }

                    @Override
                    public void onNext(String msg) {
                        ViewKit.showToast(TestActivity.this, msg + "");
                    }
                });
    }

    void jpylGetWXPayInfo() {

        String orderid = "d12365baeaf54707933f83540d760edb";

        publicApi.jpylGetWXPayInfo(orderid).map(new Func1<ResponseModel<WeiXinPayModel>,
                WeiXinPayModel>() {
            @Override
            public WeiXinPayModel call(ResponseModel<WeiXinPayModel> responseModel) {
                if (responseModel.getCode() != 0) {
                    String msg = responseModel.getMsg();
                    throw new ApiError(responseModel.getCode(), msg);
                }
                return responseModel.getData();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<WeiXinPayModel>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                            ViewKit.showToast(TestActivity.this, error.getMsg() + "");
                        }
                    }

                    @Override
                    public void onNext(WeiXinPayModel model) {
//                        ViewKit.showToast(TestActivity.this, msg + "");
                    }
                });
    }

    void jpylCheckOrderPaySuccess() {

        String orderid = "d12365baeaf54707933f83540d760edb";

        publicApi.jpylCheckOrderPaySuccess(orderid).map(new Func1<ResponseModel<OlderStateModel>,
                OlderStateModel>() {
            @Override
            public OlderStateModel call(ResponseModel<OlderStateModel> responseModel) {
                if (responseModel.getCode() != 0) {
                    String msg = responseModel.getMsg();
                    throw new ApiError(responseModel.getCode(), msg);
                }
                return responseModel.getData();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<OlderStateModel>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                            ViewKit.showToast(TestActivity.this, error.getMsg() + "");
                        }
                    }

                    @Override
                    public void onNext(OlderStateModel moel) {

                    }
                });
    }

    void jpylTryRefundOrder() {

        String orderid = "7fff31d995714548a4ff25f36a989d98";
        String userid = "859d51105bbc407c8e96f3b5e94336fe";

        publicApi.jpylTryRefundOrder(userid,orderid).map(new Func1<ResponseModel<String>,
                String>() {
            @Override
            public String call(ResponseModel<String> responseModel) {
                if (responseModel.getCode() != 0) {
                    String msg = responseModel.getMsg();
                    throw new ApiError(responseModel.getCode(), msg);
                }
                return responseModel.getMsg();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<String>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                            ViewKit.showToast(TestActivity.this, error.getMsg() + "");
                        }
                    }

                    @Override
                    public void onNext(String msg) {
                        ViewKit.showToast(TestActivity.this, msg + "");
                    }
                });
    }

    void jpylCancelOrder() {

        String orderid = "7fff31d995714548a4ff25f36a989d98";
        String userid = "859d51105bbc407c8e96f3b5e94336fe";

        publicApi.jpylCancelOrder(userid,orderid).map(new Func1<ResponseModel<String>,
                String>() {
            @Override
            public String call(ResponseModel<String> responseModel) {
                if (responseModel.getCode() != 0) {
                    String msg = responseModel.getMsg();
                    throw new ApiError(responseModel.getCode(), msg);
                }
                return responseModel.getMsg();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<String>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                            ViewKit.showToast(TestActivity.this, error.getMsg() + "");
                        }
                    }

                    @Override
                    public void onNext(String msg) {
                        ViewKit.showToast(TestActivity.this, msg + "");
                    }
                });
    }

//    private void jpylBuyerOrders() {
//
//        String userid = "859d51105bbc407c8e96f3b5e94336fe";
//        final JsonObject body = new JsonObject();
//        body.addProperty("rows", "10");
//        body.addProperty("page", "1");
//        int type = 3;
//
//        publicApi.jpylBuyerOrders(userid, body.toString(), type).map(new Func1<ResponseModel<OrderMessageModel>, OrderMessageModel>() {
//            @Override
//            public OrderMessageModel call(ResponseModel<OrderMessageModel> responseModel) {
//                if (responseModel.getCode() != 0) {
//                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
//                    throw new ApiError(messageModel);
//                }
//                return responseModel.getData();
//            }
//        })
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Subscriber<OrderMessageModel>() {
//                    @Override
//                    public void onCompleted() {
//
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//                        e.printStackTrace();
//                        if (e instanceof ApiError) {
//                            ApiError error = (ApiError) e;
//                        } else {
//                        }
//                    }
//
//                    @Override
//                    public void onNext(OrderMessageModel list) {
//
//                    }
//                });
//    }

//    private void jpylOwnerShipOrders() {
//
//        String userid = "859d51105bbc407c8e96f3b5e94336fe";
//        final JsonObject body = new JsonObject();
//        body.addProperty("rows", "10");
//        body.addProperty("page", "1");
//        int type = 3;
//
//        publicApi.jpylOwnerShipOrders(userid, body.toString(), type).map(new Func1<ResponseModel<List<OrderMessageModel>>, List<OrderMessageModel>>() {
//            @Override
//            public List<OrderMessageModel> call(ResponseModel<List<OrderMessageModel>> responseModel) {
//                if (responseModel.getCode() != 0) {
//                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
//                    throw new ApiError(messageModel);
//                }
//                return responseModel.getData();
//            }
//        })
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Subscriber<List<OrderMessageModel>>() {
//                    @Override
//                    public void onCompleted() {
//
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//                        e.printStackTrace();
//                        if (e instanceof ApiError) {
//                            ApiError error = (ApiError) e;
//                        } else {
//                        }
//                    }
//
//                    @Override
//                    public void onNext(List<OrderMessageModel> list) {
//
//                    }
//                });
//    }

//    private void jpylAreaAgentShipOrders() {
//
//        String userid = "859d51105bbc407c8e96f3b5e94336fe";
//        final JsonObject body = new JsonObject();
//        body.addProperty("rows", "10");
//        body.addProperty("page", "1");
//        int type = 3;
//
//        publicApi.jpylAreaAgentShipOrders(userid, body.toString(), type).map(new Func1<ResponseModel<List<OrderMessageModel>>, List<OrderMessageModel>>() {
//            @Override
//            public List<OrderMessageModel> call(ResponseModel<List<OrderMessageModel>> responseModel) {
//                if (responseModel.getCode() != 0) {
//                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
//                    throw new ApiError(messageModel);
//                }
//                return responseModel.getData();
//            }
//        })
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Subscriber<List<OrderMessageModel>>() {
//                    @Override
//                    public void onCompleted() {
//
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//                        e.printStackTrace();
//                        if (e instanceof ApiError) {
//                            ApiError error = (ApiError) e;
//                        } else {
//                        }
//                    }
//
//                    @Override
//                    public void onNext(List<OrderMessageModel> list) {
//
//                    }
//                });
//    }

    void jpylMyAreaAgentStatiticsForOwner() {

        String userid = "6dab72ddac9340e0bc349c99525b31ac";
        String agentid = "7a5579dcda1644d0be03cbe7d8992b39";
        int dateFrom = 0;
        int dateTo = 0;

        publicApi.jpylMyAreaAgentStatiticsForOwner(userid, agentid, dateFrom,dateTo).map(new Func1<ResponseModel<OutSituationModel>, OutSituationModel>() {
            @Override
            public OutSituationModel call(ResponseModel<OutSituationModel> responseModel) {
                if (responseModel.getCode() != 0) {
                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
                    throw new ApiError(messageModel);
                }
                return responseModel.getData();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<OutSituationModel>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                        } else {
                        }
                    }

                    @Override
                    public void onNext(OutSituationModel object) {
//                        {
//                            "code": 0,
//                                "msg": "出货查询成功",
//                                "data": {
//                            "storageNum": {
//                                "艾尔贝清": 2,
//                                        "劲络通": 5,
//                                        "ELOCK": 5,
//                                        "愈伤带": 5,
//                                        "珍宫夫": 5
//                            },
//                            "outNum": {
//                                "艾尔贝清": 3,
//                                        "劲络通": 0,
//                                        "ELOCK": 0,
//                                        "愈伤带": 0,
//                                        "珍宫夫": 0
//                            }
//                        }
//                        }
                    }
                });
    }

//    private void jpylMyAgentStatiticsForAreaAgent() {
//
//        String userid = "6dab72ddac9340e0bc349c99525b31ac";
//        String agentid = "7a5579dcda1644d0be03cbe7d8992b39";
//        int dateFrom = 0;
//        int dateTo = 0;
//
//        publicApi.jpylMyAgentStatiticsForAreaAgent(userid, agentid, dateFrom,dateTo).map(new Func1<ResponseModel<Object>, Object>() {
//            @Override
//            public Object call(ResponseModel<Object> responseModel) {
//                if (responseModel.getCode() != 0) {
//                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
//                    throw new ApiError(messageModel);
//                }
//                return responseModel.getData();
//            }
//        })
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Subscriber<Object>() {
//                    @Override
//                    public void onCompleted() {
//
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//                        e.printStackTrace();
//                        if (e instanceof ApiError) {
//                            ApiError error = (ApiError) e;
//                        } else {
//                        }
//                    }
//
//                    @Override
//                    public void onNext(Object object) {
////                        {
////                            "code": 0,
////                                "msg": "出货查询成功",
////                                "data": {
////                            "storageNum": {
////                                "艾尔贝清": 2,
////                                        "劲络通": 5,
////                                        "ELOCK": 5,
////                                        "愈伤带": 5,
////                                        "珍宫夫": 5
////                            },
////                            "outNum": {
////                                "艾尔贝清": 3,
////                                        "劲络通": 0,
////                                        "ELOCK": 0,
////                                        "愈伤带": 0,
////                                        "珍宫夫": 0
////                            }
////                        }
////                        }
//                    }
//                });
//    }

    private void jpylMyDoctorStatitics() {

        String userid = "6dab72ddac9340e0bc349c99525b31ac";
        String agentid = "7a5579dcda1644d0be03cbe7d8992b39";
        int dateFrom = 0;
        int dateTo = 0;

        publicApi.jpylMyDoctorStatitics(userid, agentid, dateFrom,dateTo).map(new Func1<ResponseModel<Object>, Object>() {
            @Override
            public Object call(ResponseModel<Object> responseModel) {
                if (responseModel.getCode() != 0) {
                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
                    throw new ApiError(messageModel);
                }
                return responseModel.getData();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<Object>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                        } else {
                        }
                    }

                    @Override
                    public void onNext(Object object) {

                    }
                });
    }

//    private void jpylAgentShipOrders() {
//
//        String userid = "6dab72ddac9340e0bc349c99525b31ac";
//        final JsonObject body = new JsonObject();
//        body.addProperty("rows", "5");
//        body.addProperty("page", "1");
//        int type = 0;
//
//        publicApi.jpylAgentShipOrders(userid, body.toString(),type).map(new Func1<ResponseModel<ProductsMessageModel>, ProductsMessageModel>() {
//            @Override
//            public ProductsMessageModel call(ResponseModel<ProductsMessageModel> responseModel) {
//                if (responseModel.getCode() != 0) {
//                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
//                    throw new ApiError(messageModel);
//                }
//                return responseModel.getData();
//            }
//        })
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Subscriber<ProductsMessageModel>() {
//                    @Override
//                    public void onCompleted() {
//
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//                        e.printStackTrace();
//                        if (e instanceof ApiError) {
//                            ApiError error = (ApiError) e;
//                        } else {
//                        }
//                    }
//
//                    @Override
//                    public void onNext(ProductsMessageModel object) {
//
//                    }
//                });
//    }

//    private void jpylAgentDPStatitics() {
//
//        String userid = "6dab72ddac9340e0bc349c99525b31ac";
//        String agentid = "7a5579dcda1644d0be03cbe7d8992b39";
//        int type = 1;
//        int dateFrom = 0;
//        int dateTo = 0;
//
//        publicApi.jpylAgentDPStatitics(userid, agentid,type,dateFrom,dateTo).map(new Func1<ResponseModel<Object>, Object>() {
//            @Override
//            public Object call(ResponseModel<Object> responseModel) {
//                if (responseModel.getCode() != 0) {
//                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
//                    throw new ApiError(messageModel);
//                }
//                return responseModel.getData();
//            }
//        })
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Subscriber<Object>() {
//                    @Override
//                    public void onCompleted() {
//
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//                        e.printStackTrace();
//                        if (e instanceof ApiError) {
//                            ApiError error = (ApiError) e;
//                        } else {
//                        }
//                    }
//
//                    @Override
//                    public void onNext(Object object) {
////                        {
////                            "code": 0,
////                                "msg": "出货查询成功",
////                                "data": {
////                            "storageNum": {
////                                "艾尔贝清": 2,
////                                        "劲络通": 5,
////                                        "ELOCK": 5,
////                                        "愈伤带": 5,
////                                        "珍宫夫": 5
////                            },
////                            "outNum": {
////                                "艾尔贝清": 3,
////                                        "劲络通": 0,
////                                        "ELOCK": 0,
////                                        "愈伤带": 0,
////                                        "珍宫夫": 0
////                            }
////                        }
////                        }
//                    }
//                });
//    }
    private void jpylMyPatientResults() {

        String userid = "6dab72ddac9340e0bc349c99525b31ac";
        String patientid = "7a5579dcda1644d0be03cbe7d8992b39";
        final JsonObject body = new JsonObject();
        body.addProperty("rows", "5");
        body.addProperty("page", "1");
        int type = 1;

        publicApi.jpylMyPatientResults(userid, patientid,body.toString(),type).map(new Func1<ResponseModel<Object>, Object>() {
            @Override
            public Object call(ResponseModel<Object> responseModel) {
                if (responseModel.getCode() != 0) {
                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
                    throw new ApiError(messageModel);
                }
                return responseModel.getData();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<Object>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                        } else {
                        }
                    }

                    @Override
                    public void onNext(Object object) {

                    }
                });
    }

    private void jpylMyPatientShipOrders() {

        String userid = "6dab72ddac9340e0bc349c99525b31ac";
        String patientid = "7a5579dcda1644d0be03cbe7d8992b39";
        final JsonObject body = new JsonObject();
        body.addProperty("rows", "5");
        body.addProperty("page", "1");
        int type = 1;

        publicApi.jpylMyPatientShipOrders(userid, patientid,body.toString(),type).map(new Func1<ResponseModel<Object>, Object>() {
            @Override
            public Object call(ResponseModel<Object> responseModel) {
                if (responseModel.getCode() != 0) {
                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
                    throw new ApiError(messageModel);
                }
                return responseModel.getData();
            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<Object>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                        if (e instanceof ApiError) {
                            ApiError error = (ApiError) e;
                        } else {
                        }
                    }

                    @Override
                    public void onNext(Object object) {

                    }
                });
    }

//    private void jpylMyPatientStatistics() {
//
//        String userid = "6dab72ddac9340e0bc349c99525b31ac";
//        String patientid = "7a5579dcda1644d0be03cbe7d8992b39";
//        int dateFrom = 0;
//        int dateTo = 0;
//
//        publicApi.jpylMyPatientStatistics(userid, patientid,dateFrom,dateTo).map(new Func1<ResponseModel<String>, String>() {
//            @Override
//            public String call(ResponseModel<String> responseModel) {
//                if (responseModel.getCode() != 0) {
//                    ErrorMessageModel messageModel = new ErrorMessageModel(responseModel.getMsg());
//                    throw new ApiError(messageModel);
//                }
//                return responseModel.getMsg();
//            }
//        })
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new Subscriber<String>() {
//                    @Override
//                    public void onCompleted() {
//
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//                        e.printStackTrace();
//                        if (e instanceof ApiError) {
//                            ApiError error = (ApiError) e;
//                        } else {
//                        }
//                    }
//
//                    @Override
//                    public void onNext(String msg) {
//
//                    }
//                });
//    }
}
